<template>
  <router-link v-if="point.isFree == 0" :to="{name: 'stadium-detail', params: {id: point.venueId}}" class="point-item">
    <div class="cover" :style="{backgroundImage:`url(${point.venueMainPic})`}" ></div>
    <div class="content-box">
      <div class="title-box">
        <div class="title">{{point.venueName}}</div>
        <van-tag class="type" :type="point.isFree === 1 ? 'success': 'primary'">{{point.isFree === 1 ? '免费': '收费'}}</van-tag>
      </div>
      <div class="address">{{point.venueAddress}}</div>
      <div class="distance">{{point.distance | distanceFilter}}</div>
      <div class="navi-btn" @click="navigateEvent"></div>
    </div>
  </router-link>
  <div v-else class="point-item">
    <div class="cover" :style="{backgroundImage:`url(${point.venueMainPic})`}" ></div>
    <div class="content-box">
      <div class="title-box">
        <div class="title">{{point.venueName}}</div>
        <van-tag class="type" :type="point.isFree === 1 ? 'success': 'primary'">{{point.isFree === 1 ? '免费': '收费'}}</van-tag>
      </div>
      <div class="address">{{point.venueAddress}}</div>
      <div class="distance">{{point.distance | distanceFilter}}</div>
      <div class="navi-btn" @click="navigateEvent"></div>
    </div>
  </div>
</template>

<script>
import { isWechat } from '@/libs/utils'
export default {
  props: {
    point: {
      required: true,
      type: Object
    },
    start: {
      required: true,
      type: Object
    }
  },
  filters: {
    distanceFilter (value) {
      return value >= 1000 ? `${parseFloat(value / 1000).toFixed(2)}km` : `${value}m`
    }
  },
  methods: {
    navigateEvent (e) {
      e.preventDefault()
      if (isWechat()) {
        this.$emit('wxNavigate', {
          lng: this.point.locationLong,
          lat: this.point.locationLat,
          name: this.point.venueName,
          address: this.point.venueAddress
        })
      } else {
        window.location.href = `https://uri.amap.com/navigation?
        from=${this.start.lng},${this.start.lat},${encodeURIComponent('我的位置')}
        &to=${this.point.locationLong},${this.point.locationLat},${encodeURIComponent(this.point.venueName)}
        &mode=car&policy=0&callnative=1`
      }
    }
  }
}
</script>

<style scoped lang="less">
.point-item{
  width: percentage(700/750);
  margin: 0 auto;
  background: #fff;
  border-radius: 5px;
  display: flex;
  padding: 10px;
  box-sizing: border-box;
  box-shadow: 0px 0px 17.64px 0.36px rgba(44, 44, 44, 0.09);

  .cover{
    width: 243/2px;
    height: 191/2px;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
  }

  .content-box{
    flex: 1;
    width: 0;
    margin-left: 18px;
    position: relative;
    .title-box{
      display: flex;
      .title{
        width: 0;
        flex: 1;
        font-weight: bold;
        color:#353434;
        font-size: 14px;
        line-height: 23px;
        .text-overflow();
      }
      .type{
        font-size: 12px;
      }
    }
    .address{
      height: 20*2px;
      color: #636363;
      font-size: 14px;
      line-height: 38/2px;
      .line-overflow(2);
    }
    .distance{
      font-size: 12px;
      color: #636363;
      margin-right: 90/2px;
      line-height: 1;
      margin-top: 16px;
    }

    .navi-btn{
      width: 92/2px;
      height: 92/2px;
      position: absolute;
      right: 0;
      bottom: 0;
      background: url("../../../assets/images/icon_navigate.png") no-repeat center center/100% 100%;
    }
  }
}
</style>
